<#import "/admin/_layout.html" as layout>
<@layout.header "菜单编辑"></@layout.header>
<@layout.body>
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-left">
                        <li class="breadcrumb-item"><a href="#">菜单</a></li>
                        <li class="breadcrumb-item active">新增</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
    <section class="content">
        <div class="container-fluid">
            <div class="card card-default">
                <form id="myForm" method="POST" action="/admin/template/menu/doSave" ok="/admin/template/menu/list">
                    <input type="hidden" name="id" value="${(menu.id)!}">
                    <div class="card-body">
                        <div class="form-group">
                            <label for="roleName">菜单名称</label>
                            <input type="text" name="menuName" class="form-control" id="menuName" placeholder="请输入菜单名称" value="${(menu.menuName)!}">
                        </div>
                        <div class="form-group">
                            <label for="roleName">菜单URL</label>
                            <input type="text" name="menuUrl" class="form-control" id="menuUrl" placeholder="请输入菜单URL" value="${(menu.menuUrl)!}">
                        </div>
                        <div class="form-group">
                            <label for="parentId">父级菜单</label>
                            <select class="form-control" id="parentId" name="parentId">
                                <#if menus?? &&(menus?size>0)>
                                    <option value="">请选择</option>
                                    <#list menus as item>
                                        <#if menu??>
                                            <#if (item.id != menu.id)>
                                                <option value="${item.id}" <#if menu.parentId?? && menu.parentId==item.id>selected</#if>>${item.menuName}</option>
                                            </#if>
                                        <#else>
                                            <option value="${item.id}">${item.menuName}</option>
                                        </#if>
                                    </#list>
                                </#if>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="roleName">排序</label>
                            <input type="number" name="sortNum" class="form-control" id="sortNum" placeholder="请输入菜单排序" value="${(menu.sortNum)!}">
                        </div>
                        <div class="box box-solid" style="width: 200px;">
                            <div class="box-header with-border ">
                                <label for="thumbnail">菜单图标</label>
                            </div>
                            <div class="box-body no-padding">
                                <img src="${spath!"static"}${(menu.menuIcon)!'/static/img/default.jpg'}"
                                     style="width: 100%;height: 200px"
                                     id="thumbnail">
                                <input type="hidden" value="${(menu.menuIcon)!}" name="menuIcon" id="articleThumbnail">
                            </div>
                            <div class="box-footer">
                                <button type="button" class="btn-image-browser btn btn-default btn-sm "
                                        for-src="thumbnail"
                                        for-input="articleThumbnail">选择图片
                                </button>
                                <a href="javascript:;" style="padding-left: 15px" id="removeThumbnail">移除</a>
                            </div>
                        </div>
                        <div class="form-group">
                            <#assign _target=(menu.target)!"_self" />
                            <label for="target">目标</label>
                            <select class="form-control" id="target" name="target">
                                <option value="_self" <@selectedIf value=(_target =="_self")/>>当前页</option>
                                <option value="_target" <@selectedIf value=(_target =="_target")/>>新窗口</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <#assign _status=(menu.status)!"show" />
                            <label for="status">状态</label>
                            <select class="form-control" id="status" name="status">
                                <option value="show" <@selectedIf value=(_status =="show")/>>显示</option>
                                <option value="hidden" <@selectedIf value=(_status =="hidden")/>>隐藏</option>
                            </select>
                        </div>
                    </div>
                    <div class="card-footer">
                        <button type="submit" class="btn btn-primary">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </section>
</@layout.body>
<@layout.script>
    <script>
        $("#removeThumbnail").on("click", function () {
            $("#thumbnail").attr("src", "/static/img/default.jpg");
            $("#articleThumbnail").val("");
        })
        $(function () {
            submitForm({
                menuName: { required: true},
                menuUrl: { required: true}
            },{
                menuName: {required: "请输入菜单名称"},
                menuUrl: {required: "请输入菜单URL"}
            })
        });
    </script>
</@layout.script>